﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using LunchList.Controllers;
using LunchList.ViewModels;
using LunchListCore.Entities;
using LunchListCore.Interfaces.Agents;
using LunchListCore.Interfaces.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

namespace LunchList.Tests
{
	[TestClass]
	public class HomeControllerTests
	{
		[TestMethod]
		public void IndexTest()
		{
			Mock<ILunchAgent> mockLunchAgent = new Mock<ILunchAgent>();

			IList<DateTime> datesToReturn = new List<DateTime>()
			{
				new DateTime(2052, 9, 21),
				new DateTime(2052, 9, 22),
				new DateTime(2052, 9, 23),
				new DateTime(2052, 9, 24)
			};
			mockLunchAgent.Setup(x => x.GetUpcomingEventDates()).Returns(() => datesToReturn);

			HomeController homeController = new HomeController();
			homeController.LunchAgent = mockLunchAgent.Object;

			ViewResult viewResult = homeController.Index("9-21-2052") as ViewResult;
			Assert.IsNotNull(viewResult, "The result is not a view result");

			//Assert.IsTrue(viewResult.Contains("Home Page"));
		}

		[TestMethod]
		public void GetGuestLists()
		{
			Mock<ILunchAgent> mockLunchAgent = new Mock<ILunchAgent>();

			Dictionary<IEvent, IList<IGuest>> datesToReturn = new Dictionary<IEvent, IList<IGuest>>();

			IList<IGuest> guests = new List<IGuest>()
			{
				new Guest()
				{
					AdUserId = "NATest",
					GuestId = 1
				}
			};

			datesToReturn.Add(new Event()
			{
				EventId = 1,
				EventName = "Test Event",
				EventDate = new DateTime(2014, 5, 23)
			}, guests);

			DateTime eventDate = new DateTime(2052, 9, 21);
			mockLunchAgent.Setup(x => x.GetGuestsAndEvents(eventDate)).Returns(() => datesToReturn);

			HomeController homeController = new HomeController();
			homeController.LunchAgent = mockLunchAgent.Object;

			Mock<IGuestContext> mockGuestContext = new Mock<IGuestContext>();
			mockGuestContext.Setup(x => x.User).Returns(() => guests[0]);
			homeController.GuestContext = mockGuestContext.Object;

			HomeViewModel homeViewModel = new HomeViewModel()
			{
				SelectedDate = eventDate
			};
            //PartialViewResult viewResult = homeController.GetGuestLists(guestModel) as PartialViewResult;
            //Assert.IsNotNull(viewResult, "The result is not a partial view result result");
            //Assert.AreSame("_GuestLists", viewResult.ViewName);
			
		}

		[TestMethod]
		public void ModifyGuestListTest()
		{
			Mock<ILunchAgent> mockLunchAgent = new Mock<ILunchAgent>();

			IList<GuestListItemViewModel> guestListToReturn = new List<GuestListItemViewModel>();

			IReservation mockReservation = new Reservation();

			GuestListViewModel mockGuestListViewModel = new GuestListViewModel()
			{
				EventId = 3,
				ModifyAction = "RSVP"
			};

			IList<IGuest> guests = new List<IGuest>()
			{
				new Guest()
				{
					AdUserId = "NATest",
					GuestId = 1
				}
			};
			HomeController homeController = new HomeController();
			homeController.LunchAgent = mockLunchAgent.Object;

			Mock<IGuestContext> mockGuestContext = new Mock<IGuestContext>();
			mockGuestContext.Setup(x => x.User).Returns(() => guests[0]);
			homeController.GuestContext = mockGuestContext.Object;

			mockLunchAgent.Setup(x => x.AddReservation(mockGuestContext.Object.User, mockGuestListViewModel)).Returns(() => mockReservation);
			mockLunchAgent.Setup(x => x.GetGuests(mockGuestListViewModel)).Returns(() => guests);


			PartialViewResult viewResult = homeController.ModifyGuestList(mockGuestListViewModel) as PartialViewResult;
			Assert.IsNotNull(viewResult, "The result is not a partial view result result");
			Assert.AreSame("_GuestList", viewResult.ViewName);
		}
	}
}